/*
 * @Author: your name
 * @Date: 2021-04-14 10:25:28
 * @LastEditTime: 2021-04-19 14:12:40
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: /flutter_demo/lib/pages/tabs/Category.dart
 */
import 'dart:io';

import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
import 'package:flutter_demo/pages/Forms.dart';
import 'package:package_info/package_info.dart';
import 'package:path_provider/path_provider.dart';
import 'package:open_file/open_file.dart';

class CategoryPage extends StatefulWidget {
  @override
  _CategoryPageState createState() => _CategoryPageState();
}

class _CategoryPageState extends State<CategoryPage> {
  // Future<void> _checkPermission() async {
  //   if (Theme.of(context).platform == TargetPlatform.android) {
  //     final status = await Permission.storage.status;
  //     if (status != PermissionStatus.granted) {
  //       final result = await Permission.storage.request();
  //       if (result == PermissionStatus.granted) {
  //         return true;
  //       }
  //     } else {
  //       return true;
  //     }
  //   }
  //   return false;
  // }

  // // 下载应用
  // _download() async {
  //   var permission = await this._checkPermission();
  //   if (permission) {
  //     final directory = await getExternalStorageDirectory();
  //     String _localPath = directory.path;
  //     String _appName = '';
  //     String _savePath = '$_localPath/$_appName';
  //     String apkUrl = '';

  //     await Dio().download(apkUrl, _savePath,
  //         onReceiveProgress: (received, total) {
  //       if (total != -1) {
  //         print((received / total * 100).toStringAsFixed(0) + '%');
  //       }
  //     });
  //     print(_savePath);
  //     await OpenFile.open(_savePath,
  //         type: "application/vnd.android.package-archive");
  //   } else {
  //     print('没有权限');
  //   }
  // }

  // 应用存储目录
  _getDir() async {
    Directory tempDir = await getTemporaryDirectory();
    String tempPath = tempDir.path;

    Directory appDocDir = await getApplicationDocumentsDirectory();
    String appDocPath = appDocDir.path;

    Directory directory = await getExternalStorageDirectory();
    String storageDir = directory.path;
    print(storageDir);
  }

  // 应用版本信息
  _getInfo() async {
    PackageInfo packageInfo = await PackageInfo.fromPlatform();

    String appName = packageInfo.appName;
    String packageName = packageInfo.packageName;
    String version = packageInfo.version;
    String buildNumber = packageInfo.buildNumber;
    print(version);
  }

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    this._getInfo();
    this._getDir();
  }

  @override
  Widget build(BuildContext context) {
    return DefaultTabController(
        length: 2,
        child: Scaffold(
            appBar: AppBar(
              title: Row(
                children: <Widget>[
                  Expanded(
                    child: TabBar(
                      // isScrollable: true,
                      indicatorColor: Colors.blue,
                      labelColor: Colors.red,
                      unselectedLabelColor: Colors.white,
                      indicatorSize: TabBarIndicatorSize.label,
                      tabs: <Widget>[Tab(text: '热销'), Tab(text: '推荐')],
                    ),
                  )
                ],
              ),
            ),
            body: TabBarView(children: <Widget>[
              ListView(
                children: <Widget>[
                  ListTile(
                    title: Text('热销'),
                  ),
                  ListTile(
                    title: Text('热销'),
                  ),
                ],
              ),
              ListView(
                children: <Widget>[
                  ListTile(
                    title: Text('推荐'),
                  ),
                  ListTile(
                    title: Text('推荐'),
                  ),
                ],
              )
            ])
            // Column(
            //   crossAxisAlignment: CrossAxisAlignment.start,
            //   mainAxisAlignment: MainAxisAlignment.center,
            //   children: <Widget>[
            //     RaisedButton(
            //       onPressed: () {
            //         Navigator.of(context).push(MaterialPageRoute(
            //             builder: (context) => FormsPage(title: '我是跳转传值')));
            //       },
            //       child: Text('跳转到表单传值'),
            //       color: Theme.of(context).accentColor,
            //       textTheme: ButtonTextTheme.primary,
            //     )
            //   ],
            // )
            ));
  }
}
